uniform mat4 	uPMatrix;
uniform mat4 	uMVMatrix;
uniform vec3	lightDir;

attribute vec4	position;
attribute vec2	uv;
attribute vec3	normal;
attribute vec3	tangent;

//varying highp   vec3 pos;
varying vec2	texCoords;
varying	vec3	tangentLight;
varying vec3	tangentView;
//varying highp	float selfShadow;
varying vec3	tangentToWorldY;

void main()
{

	vec3 pos		= (uMVMatrix * position).xyz;
	texCoords		= uv;
	
	// compute tangent space
	vec3 n			= normalize(	vec3(uMVMatrix * vec4(normal, 0.0))		);
	vec3 t			= normalize(	vec3(uMVMatrix * vec4(tangent, 0.0))	);
	vec3 b			= cross(n, t);
	mat3 tspacemat	= mat3(t, b, n);
	
	// compute light and view position in tangent space
	tangentLight	= lightDir * tspacemat;
	tangentView		= pos * tspacemat;

	// helps for reflection map lookups from tangent space
	tangentToWorldY = vec3(t.y, b.y, n.y);

	// compute self shadow (for correcting normal map specular term)
	//selfShadow = clamp(tangentLight.z * 4.0, 0.0, 1.0);

	gl_Position = uPMatrix * uMVMatrix * position;
	
}